package com.android.helix;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;


public class HelixSurfaceView extends GLSurfaceView{
	public HelixSurfaceView(Context context){
        super(context);
        setEGLContextClientVersion(2);
        mRender = new HelixRenderer(context);
        setRenderer(mRender );
	}
	
	public boolean onTouchEvent(MotionEvent me) {

		Log.e(Utils.TAG, "xpos=" + mDX);
		Log.e(Utils.TAG, "ypos=" + mDY);

		if (me.getAction() == MotionEvent.ACTION_DOWN) {
			xpos = me.getX();
			ypos = me.getY();
			return true;
		}

		if (me.getAction() == MotionEvent.ACTION_UP) {
			xpos = -1;
			ypos = -1;
			mDX = 0;
			mDY = 0;
			return true;
		}

		if (me.getAction() == MotionEvent.ACTION_MOVE) {
			float xd = me.getX() - xpos;
			float yd = me.getY() - ypos;

			xpos = me.getX();
			ypos = me.getY();

			mDX = xd / -2f;
			mDY = yd / -2f;
			mRender.mScene3D.mDX += mDX;
			mRender.mScene3D.mDY += mDY;
			return true;
		}
		
		
		try {
			Thread.sleep(15);
		} catch (Exception e) {
			// No need for this...
		}

		return super.onTouchEvent(me);
	}

	float xpos, ypos;
	float mDX, mDY;
	HelixRenderer mRender;
}